<?php require("common.inc.php"); ?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link rel="Bookmark" href="favicon.ico" >
<link rel="Shortcut Icon" href="favicon.ico" />
<script type="text/javascript" src="/public/home/js/jquery.min.js"></script>
<!--[if lt IE 9]>
<script type="text/javascript" src="/public/home/js/html5.js"></script>
<![endif]-->
<script type="text/javascript" src="/public/home/js/jquery.cycle.all.min.js"></script>
<link href="/public/home/css/H-ui.reset.css" rel="stylesheet" type="text/css" />
<link href="/public/home/css/style.css" rel="stylesheet" type="text/css" /><!--自己的样式-->
<link href="/public/home/css/plugs.css" rel="stylesheet" type="text/css" /><!--自己的样式-->
</head>
<body class="bg-df">
<p style="text-align: center;font-size: 24px;color: #fff;font-weight: 900;margin-top: 100px;">
<?php
$backurl=geturls();
if(trim($_POST["act"])!="add") {
    locationurl("index.php");
}
$areg=$config->getregmust();

$arr['uname']=checkstr($_POST['userid']);
		//校验验证码
		$yzm=checkstr(trim($_POST["vcode"]));
		$code=strtolower($_SESSION["code"]);
		if($code!=$yzm){
			echo "您输入的验证码不正确";exit;
		}

		//推荐人为空则默认为admin
        if ( empty($_POST['tuname'])){
            $_POST['tuname'] = 'admin';
        }


        $arr['introducer_id']=checkstr($_POST['tuname']);
		$arr['user_level']=0;
		$arr['user_title']=$arr['user_level'];
		$arr['openuser_cost_coin']=getlevel($arr['user_level'],1); //新增

		$s=chkreginfo($arr);
		if(!empty($s)){
            echo $s;exit;
        }
		$arr['regist_time']=$SITETIME;
		$arr['open_time']=$SITETIME;
		$arr['is_passed']=1;
		$arr['register_uname']='0|0';

		$arm['uname']=$arr['uname'];

		// $arm['real_name']=checkstr(trim($_POST['username']));
  		$arm['nick_name']=$arr['uname'];
		$arm['user_jibie']=$arr['user_level'];
		$tmprgpwd1=checkstr($_POST['rgpwd1']);
		$rmprgpwd2=checkstr($_POST['rgpwd2']);
		$arm['rgpwd1']=md5(md5($tmprgpwd1.SITEENCRYPT));
		$arm['rgpwd2']=md5(md5($rmprgpwd2.SITEENCRYPT));
		// $arm['mbq']=is_null($_POST['mbq'])?0:$_POST['mbq'];
		// $arm['rgmba']=checkstr($_POST['rgmba']);
		$arm['phone']=checkstr($_POST['rgmobile']);
		//国际区号
		$arm['gj_code']=$_SESSION['nat']?$_SESSION['nat']:86;

		$arr['vic_address']="";
		$arr['vic_account']=0;
		$arr['vic_pass']="";
		$arr['vic_block_number']=0;


		// $tphone=checkstr($_POST['tphone']);//推荐人手机
		/*
		$bank['bankno']=checkstr($_POST['bankno']);
		$bank['bankname']=checkstr($_POST['bankname']);
		$bank['customer_name']=checkstr($_POST['username']);
		$bank['add_time']=time();
		$bank["is_default"]=1;
		$bank['uname']=$arr['uname'];
        */
		// if(isset($areg['rgmbq'])&&$areg['rgmbq']==0){
		// 	if($arm['mbq']==-1){
		// 		echo "请选择密保问题";
		// 		exit;
		// 	}
		// }
		if(empty($arm['uname'])) {
			echo "请输入用户名";
			exit;
		}
		if($member->user_exists($arm['uname'])) {
			echo "用户名已被使用！";
			exit;
		}
		if(empty($arm['phone'])) {
			echo "请输入手机号码";
			exit;
		}
		if($member->mobile_exists($arm['phone'])) {
			echo "手机号码已被使用";
			exit;
		}
		$ttname = checkstr(trim($_POST['tuname']));
		if(!$member->tu_exists($ttname)) {
			echo "推荐人不存在";
			exit;
		}
		//判断推荐人手机是否存在
		// if(!$member->mobile_exists($tphone)) {
		// 	echo "推荐人手机号码不存在";
		// 	exit;
		// }

		// if(!$member->user_mobile_match($ttname,$tphone)){
		// 	echo "推荐人用户名和手机号不匹配！";
		// 	exit;
		// }
		/*
		if($bank['bankname']==''){
			echo '请选择收款方式';
			exit;
		}
		if($bank['bankno']==''){
			echo '请输入收款账户';
			exit;
		}
		$banks=$member->get_bank($bank['bankno']);
		if(!empty($banks)){
			echo '此账户已被使用';
			exit;
		}
		*/
	try{
		$db->begintransaction();
		$rt=fun_insertTime();
		$arr['open_classify']=$rt["id"];
		$sql=getinsertsql($arr,'ld_user_account','user_level,user_title');
		$db->query($sql,5);
		$arm['id']=$db->fval;

		$sql=getinsertsql($arm,'ld_user_info','user_jibie,sex,mbq');
		$db->query($sql,5);

		// $sql=getinsertsql($bank,"ld_bank");
	 //    $db->sitedbexec($sql);
		//满足条件注册赠送x个赞币
		$time=intval(time());
		if ($time > strtotime($GLOBALARR['timestart']) && $time <= (strtotime($GLOBALARR['timeend'])+24*3600)) {
			$db->query( "update ld_user_account set presentcoin = presentcoin +'".$GLOBALARR['presentcoin']."' where uname='".$arm['uname']."'",4);
		}
		record_log("注册会员".$arr['uname'].',id为'.$arm['id'],0);
		auto_recomm($ttname);
		$db->committransaction();

		$_SESSION['userid']=$arm['id'];
		$_SESSION["savetime"]=time();//辅助判断登录时间
		echo " <script type='text/javascript' src='/public/home/js/layer/layer.js'></script>
                <script type='text/javascript'>layer.msg('注册成功！欢迎加入".$GLOBALARR['sytitle']."');
                setTimeout('tiaozhuan()',1000);function tiaozhuan(){window.location.href='login.php';}</script>";
		  exit;
	}catch(PDOException $e){
		$db->rollbacktransaction();
        echo "注册失败，请重新注册";
		exit;
	}
?>
</p>
</body>
</html>